<template>
  <div>
    <f-table ref='table' size='small' rowKey='paymentId' :columns='columns' :scroll='{x:true}' :multiple='false' :operator='operator' :params='queryParam' :api='api.tasktodo' handler='refundAmountTab1TodoListHandler'>
      <span slot='amountType' slot-scope='text, record, index'>
         <a-tag color='#87d068' v-if="text=='RefundDeposit'">退保证金</a-tag>
         <a-tag color='#108ee9' v-if="text=='RefundHk'">退货款</a-tag>
         <a-tag color='#6B8E23' v-if="text=='CbReturn'">退资保金</a-tag>
      </span>
      <span slot='taskName' slot-scope='text, record, index'>
          <a-tag color='#FF6103' @click='processImg(record)'>{{ record.taskName }}</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
          <template>
          <a v-if="record.endTime==''&&record.assignee!=''&& record.assignee!='' && record.taskName=='出纳支付'" @click='$refs.drawer.showDrawer(record)'>办理</a>
            <a v-if="record.assignee!='' && record.taskName!='出纳支付'" @click='$refs.refundHkDrawer.showDrawer(record)'>办理</a>
            <a v-if="record.assignee==''||record.assignee==''" @click='claimTask(record)'>认领</a>
            <a-divider type='vertical' />
             <span v-if='record.amountType=="CbReturn"'>
               <a href='javascript:;' @click="$refs['refundDetailsDrawer'].showDrawer(record)">查看</a>
               <a-divider type='vertical' />
             </span>
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime==''">
                <a href='javascript:;' @click='unClaimTask(record)'>取消认领</a>
              </a-menu-item>
                <a-menu-item>
                <a href='javascript:;' @click='processImg(record)'>流程图</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='printPayment(record.paymentId)'>查看单据</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <task-todo-drawer ref='drawer' @success='onLoad' handler-name='refundAmountFormTaskDataHandler'></task-todo-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <refund-bond-drawer ref='refundDetailsDrawer'></refund-bond-drawer>
    <refund-hk-drawer ref='refundHkDrawer' @success='onLoad'></refund-hk-drawer>
    <print-modal ref='printModal' :showPrint='false'></print-modal>
  </div>
</template>
<script>

import api from "../../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import TaskTodoDrawer from "../tasktodo_drawer"
import {processMixins} from "@/core/mixins/processMixins"
import RefundBondDrawer from "./components/refund_bond_drawer"
import RefundHkDrawer from "@/views/module/haiying/tasktodo/refundamount/components/refund_hk_drawer"
import PrintModal from "@/views/module/haiying/print/print_modal"
export default {
  name: "TableList",
  components: {
    PrintModal,
    RefundHkDrawer,
    ProcessImage,
    RefundBondDrawer,
    TaskTodoDrawer
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      scroll: { x: 2250 },
      processInstanceId: "",
      processImageVisible: false,
      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "申请日期",
          align: "center",
          width: "140px",
          dataIndex: "amountDate"
        },
        {
          title: "单号",
          align: "center",
          width: "140px",
          dataIndex: "paymentNo"
        },
        {
          title: "单据类型",
          align: "center",
          width: "100px",
          dataIndex: "amountType",
          scopedSlots: { customRender: "amountType" }
        },
        {
          title: "申请金额",
          align: "center",
          width: "100px",
          dataIndex: "amount"
        },
        {
          title: "收款方",
          align: "left",
          width: "130px",
          ellipsis: true,
          dataIndex: "payeeName"
        },

        {
          title: "收款银行",
          align: "left",
          width: "150px",
          ellipsis: true,
          dataIndex: "bankName"
        },
        {
          title: "收款账户",
          align: "left",
          width: "150px",
          ellipsis: true,
          dataIndex: "bankNo"
        },
        {
          title: "创建日期",
          align: "center",
          width: "130px",
          dataIndex: "createTime"
        },

        {
          title: "制单人",
          align: "center",
          width: "100px",
          dataIndex: "nickName"
        },
        {
          title: "审批状态",
          align: "left",
          fixed: "right",
          dataIndex: "taskName",
          scopedSlots: { customRender: "taskName" }
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "155px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    /**
     * 取消认领
     * @param task
     */
    unClaimTask(task) {
      this.http.put(this, {
        url: this.api.tasktodo.unclaim,
        data: {
          taskId: task.taskId
        },
        success(me, data) {
          me.$refs["table"].refresh(false)
        }
      })
    },
    /**
     * 流程图
     * @param task
     */
    processImg(task) {
      this.processInstanceId = task.processInstanceId
      this.processImageVisible = true
    },
    //打印单
    printPayment(paymentId) {
      this.$refs["printModal"].open(paymentId, 2, "RefundHk")
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    }
  }
}
</script>
